<!-- 待收来电>收电 -->
<template>
	<view>
		<van-cell-group>
		  <van-cell center title="标题"  :value="formData.title" />
      <van-cell center title="呈送领导" :value="formData.csldToName" />
		  <van-cell center title="发往"  :value="formData.mainToName" />
		  <van-cell center title="抄送"  :value="formData.copyToName" />
		  <van-cell center title="其他单位"  :value="formData.otherUnit" />
		  <van-cell center title="等级"  :value="formData.emergencyLevelName" />
		  <van-cell center title="重要电报"  :value="formData.attentionStatus=='0'?'否':'是'" />
		  <van-cell center title="发电号"  :value="fdh" value-class="ext-black text-bold"/>
		  <van-cell center title="拟稿日期"  :value="formData.drafteTime" />
		  <van-cell center title="份数"  :value="formData.approvePart" />
		  <van-cell center title="每份页数"  :value="formData.eachPage" />
		  <van-cell center title="拟稿人"  :value="formData.drafterName" />
		  <van-cell center title="电话"  :value="formData.draftePhone" />
		  <van-cell center title="拟稿单位"  :value="formData.drafterDeptName" />
		  <van-cell center title="落款单位"  :value="formData.signDept" />
		  <van-cell center title="登记人"  :value="formData.registerName" />
		  <van-cell center title="登记时间"  :value="formData.createTime" />
		  <van-cell center title="备注"  :value="formData.remark" />

      <view class="opinion">
        <text class="opinion-left">发送件</text>
        <view class="opinion-right">
          <view v-for="item in detailBody.doc" @click="lx.openFile(item, formData.annexId)">
<!--            <text class="text-blue">{{ item.attachName }}</text>-->
            <text class="text-blue">{{ formData.title }}</text>
          </view>
        </view>
      </view>

      <view class="opinion">
        <text class="opinion-left">附件</text>
        <view class="opinion-right" v-if="this.util.isNotEmpty(detailAttachment)">
          <view v-for="item in detailAttachment" @click="lx.openFile(item, formData.annexId)">
            <!--<text class="text-blue">{{ item.attachName }}</text>-->
            <text class="text-blue">{{ formData.title }}</text>
          </view>
        </view>
      </view>
		</van-cell-group>

		<register ref="register" :showRegister="showRegister"  @closeRegister="closeRegister"></register>
		<forward ref="forward" :showForward="showForward"  @closeForward="closeForward"></forward>
		<div style="height: 5rem;">
			<van-tabbar v-model="active" >
				<van-tabbar-item  v-for="item in barList" :name="item.name" :icon="item.icon" @click="onClick(item.name)">{{item.value}}
				</van-tabbar-item>
			</van-tabbar>
		</div>
	</view>
</template>

<script>
	import { Dialog } from 'vant';
	import register from 'pages/jgj/components/receiveMsgDoc/compo-register';
	import forward from 'pages/jgj/components/receiveMsgDoc/compo-forward';
	export default {
		components: {
			register,//登记组件
			forward//仅转发组件
		},
      onLoad: async function (option) {
        await this.$onLaunched //解決bug：执行完onLaunch后再执行页面onLoad
			this.userInfo = this.cache.get('userInfo')//从缓存获取用户信息
			//从地址栏获取fdId
			this.fdId= option.fdId
			//acceptType:1-已签，0-待收
			this.acceptType = option.acceptType
			this.uuid = option.uuid
			//如果acceptType==1 已签，则下边的tab按钮隐藏或禁止点击
			if(this.util.isNotEmpty(this.acceptType)){
				if(this.acceptType == '1'){
					this.barList.forEach((item,index)=>{
						if(item.name == 'receipt'){
							this.barList.splice(index,1)
						}
					})
				}
			}
			if(this.util.isNotEmpty(this.fdId)){
				this.getSdDetail(this.fdId)//通过fdId获取收电待办详情数据
			}
		},
		data() {
			return {
				fdId:'',
				acceptType:'',
				uuid:'',
				userInfo:{},//当前登录用户信息，目前先从缓存中获取
				active: '',
				formData:{},
				fdh:'',//发电号
				detailBody:{},//发送件
				detailAttachment:[],//附件
				showRegister:false,//登记子组件是否显示
				showForward:false,//仅转发组件显示
				barList: [{
				  name: 'register',
				  icon: 'edit',
				  value: '登记',
				},
				  {
					name: 'receipt',
					icon: 'records',
					value: '签收',
				  },
				  {
					name: 'forward',
					icon: 'replay',
					value: '仅转发',
				  }
				]
					};
				},
		methods: {
			//点击tabbar
			onClick(item){
				//登记
				if(item == 'register'){
					this.showRegister = true
					this.$refs.register.getDetail(this.fdId,this.uuid)//调用子组件的方法
				}
				//签收
				if(item == 'receipt'){
					Dialog.confirm({
					    title: '确认操作',
					    message: '确定要进行签收操作？',
					}).then(() => {
					    // on confirm
						this.accept()
					}).catch(() => {
						// on cancel
					});
				}
				//仅转发
				if(item == 'forward'){
					this.showForward = true
					this.$refs.forward.getDetail(this.fdId,this.uuid)//调用子组件的方法
				}
			},
			//关闭修改公文要素
			closeRegister(showRegister){
				this.showRegister = false
			},
			closeForward(data){
				this.showForward = false
			},
			getSdDetail(fdId){
				//通过proInstId获取收电待办详情数据
				const _this = this
				this.$http({
				  url: this.$http.adornUrl(`/caac/oa/doc/sendinfo/fdinfo/`+fdId),
				  method: 'get',
				  params: this.$http.adornParams({
					  'systemKey': this.userInfo.systemKey,//固定值
					  'systemFlag': this.userInfo.systemFlag//固定值
				  })
				}).then(({data}) => {
					console.log("获取收电详情--data: " + JSON.stringify(data));
					if(data.code==200){
						this.formData = data.data
						this.getCaacBody(data.data.annexId)//获取发送件
						this.getCaacAttachment(data.data.annexId)//获取附件数据
						if(this.util.isNotEmpty(this.formData.fdWord) && this.util.isNotEmpty(this.formData.fdYear)){
							this.fdh=this.formData.fdWord+'〔'+this.formData.fdYear+'〕'+this.formData.fdNum+'号'
						}else{
							this.fdh = this.formData.fdWord
						}
					}
				})
			},
			//获取发送件
			getCaacBody(annexId){
				const _this = this
				this.$http({
				  url: this.$http.adornUrl(`/caac/oa/component/maintext/proInstId/`+annexId),
				  method: 'get',
				  params: this.$http.adornParams({
					  'systemKey': this.userInfo.systemKey,//固定值
					  'systemFlag': this.userInfo.systemFlag//固定值
				  })
				}).then(({data}) => {
					if(data.code==200){
						_this.detailBody =data.data
					}
					console.log("获取发送件: " + JSON.stringify(_this.detailBody));
				})
			},

			//获取附件数据
			getCaacAttachment(annexId){
				const _this = this
				this.$http({
				  url: this.$http.adornUrl(`/caac/oa/component/attachmentupload/attachmentinfoOrderBy`),
				  method: 'get',
				  params: this.$http.adornParams({
					  'bizId': annexId,
					  'attachTypeId':'pageBody_uploadFile',
					  'systemKey': this.userInfo.systemKey,//固定值
					  'systemFlag': this.userInfo.systemFlag,//固定值
				  })
				}).then(({data}) => {
					if(data.code==200){
						this.detailAttachment =data.data
					}
					console.log("附件: " + JSON.stringify(_this.detailAttachment));
				})
			},
			//签收
			accept(){
				const _this = this
				this.$httploading({
				  url: this.$http.adornUrl(`/caac/oa/doc/hbjgj/fdpengding/acceptType`),
				  method: 'post',
				  data:this.uuid,
				  params:{
					  'systemKey': this.cache.get('userInfo').systemKey,//固定值
					  'systemFlag': this.cache.get('userInfo').systemFlag,//固定值
				  }
				}).then(({data}) => {
					console.log("签收结果-->>: " + JSON.stringify(data));
					if(data.code==200){
						_this.$toast(data.data.message)//签收成功
						//隐藏下边的签收菜单
						this.barList.forEach((item,index)=>{
							if(item.name == 'receipt'){
								this.barList.splice(index,1)
							}
						})
					}else{
						_this.$toast(data.message+' code:'+data.code)
					}

				})

			},
		},
	}
</script>

<style scoped>
	/* 意见相关样式 */
	.opinion{
		display: flex;
		flex-direction: column;
		margin: 0 32rpx;
		padding: 20rpx 0rpx;
		overflow: hidden;
		font-size: 28rpx;
		line-height: 24px;
		border-bottom: 1px solid #ebedf0;

	}
	.opinion .opinion-title{
		text-align: left;
		padding-bottom: 14rpx;
	}
	.opinion .opinion-box{
		margin-bottom: 20rpx;
	}
	.opinion .opinion-left{
		text-align: left;
		color: #323233;
	}
	.opinion .opinion-right{
		text-align: right;
		color: #969799;
	}
	.opinion .opinion-right .opinion-user{
		font-weight: 400;
		color: #000000;
	}
	.opinion .opinion-right .opinion-date{
		color: #323233;
		margin-left: 20rpx;
	}
		.van-cell__title {
			min-width: 20%;
		}
		.van-cell__value {
			min-width: 80%;
		}
</style>
